import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/modules/autonym/api/autonymApi.dart';
import 'package:honeypotflutter/modules/autonym/pag/autonym_success/view.dart';
import 'package:honeypotflutter/public/public_get.dart';
import 'package:honeypotflutter/public/public_picker.dart';
import 'package:honeypotflutter/publicBussine/express/bussine_express_logic.dart';

class AutonymExpressLogic extends GetxController {
  TextEditingController expressController = TextEditingController();
  TextEditingController numberController = TextEditingController();

  ExpressLogic _logic = Get.find<ExpressLogic>();

  /// 点击按钮
  RxBool enable = RxBool(false);

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    expressController.addListener(() {
      enable.value = expressController.text.isNotEmpty && numberController.text.isNotEmpty;
    });

    numberController.addListener(() {
      enable.value = expressController.text.isNotEmpty && numberController.text.isNotEmpty;
    });
  }

  /*
  * 选择快递公司
  * */
  selectExpressList() async {
    List<String> listName = _logic.expressList.map((e) => e.fullName ?? "").toList();
    HLPicker.showPicker(
        data: listName,
        onConfirm: (value, index) {
          expressController.text = value;
        });
  }

  /*
  * 绑定信息
  * */
  bindExpress() async {
    await AutonymApi.bindExpress(expressController.text, numberController.text);
    HLGet.to(AutonymSuccessPage());
  }
}
